\ FORTH.SCR 12:00 10/31/92 Special version of FORTH.SCR for FIRST/FORTH Copyright (c) 1986-1990 Laboratory Microsystems, Inc. All Rights Reserved FIRST/FORTH is a copyrighted program distributed as shareware. If you use this program, you must register your copy as described in the file READ.ME. The registration fee of $49.95 (plus $5 shipping/handling) also provides you a copy of the book *Programming for the Utter Beginner*, which contains complete information about FIRST/FORTH. Pay the fee to: FIRST/FORTH Registration Laboratory Microsystems, Inc. 12555 West Jefferson Boulevard Suite 202 Los Angeles, CA 90066 \ What this file is 12:00 10/31/92 \ On boot-up, UR/FORTH uses as a default file FORTH.SCR, which \ contains source code for various utilities: routines that \ convert screen files to text files, text files to screen \ files, print source code in a convenient format on \ Epson-compatible or LaserJet-compatible printers, asynchronous\ drivers, breakpoint utilities, and the like. These routines \ are useful both in themselves and as examples of Forth code. \ In FIRST/FORTH you have an abbreviated version of FORTH.SCR, \ which contains a set of timer words and a random number \ generator. Both these are also in UR/FORTH's FORTH.SCR. \ With UR/FORTH you also get source code to the screen editor, \ so that you can tailor it to your own preferences. \ Timer module 12:00 10/31/92 VARIABLE TickCount : !TIMER ( -- ) 65534 TickCount ! \ initial tick count TickCount TICKER ABORT" Can't initialize timer" ; : @TIMER ( -- d ) \ elapsed time in centiseconds 65534 TickCount @ - 10 UM* 182 UM/MOD \ seconds + fraction >R 100 182 */ S>D R> 100 M* D+ \ convert to 100ths TickCount -TICKER ; \ disable tick counter : .TIMER ( -- ) @TIMER <# # # ASCII . HOLD #S #> TYPE SPACE ; \ Random number generator 12:00 10/31/92 \ Given an argument, returns a pseudo-random number between \ 0 and that argument. The pseudo-random sequence can be \ altered by changing the seed. VARIABLE SEED : random ( -- n ) \ 0 <= n <= 32767 SEED @ 259 * 3 + 32767 AND DUP SEED ! ; : RANDOM ( n1 -- n2 ) \ 0 <= n2 < n1 random M* 32768 UM/MOD NIP ;